package com.tengju.data.domain.model.clickhouse.brand;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

@Getter
@AllArgsConstructor
public enum BrandMarketSortOrderType {

    //sellAccount 降序
    ORDER_SELLACOUNT_DESC("sellAccount","desc","降序"),
    //sellAccount 升序
    ORDER_SELLACOUNT_ASC("sellAccount","asc","升序"),
    //makeMembers 降序
    ORDER_MAKEMEMBERS_DESC("makeMembers","desc","降序"),
    //makeMembers 升序
    ORDER_MAKEMEMBERS_ASC("makeMembers","asc","升序"),
    //makeMembers 降序
    ORDER_HOLDRATIO_DESC("holdRatio","desc","降序"),
    //makeMembers 升序
    ORDER_HOLDRATIO_ASC("holdRatio","asc","升序");

    /**
     * 排序字段
     */
    private String orderColumn;
    /**
     * 排序规则
     */
    private String orderType;
    /**
     * 描述
     */
    private String desc;

    public static BrandMarketSortOrderType fromSortType(String orderColumn,String orderType) {
        //默认降序
        if (StringUtils.isEmpty(orderType) || StringUtils.isEmpty(orderColumn)) {
            return BrandMarketSortOrderType.ORDER_SELLACOUNT_DESC;
        }

        for (BrandMarketSortOrderType type : BrandMarketSortOrderType.values()) {
            if (type.orderType.equals(orderType) && type.orderColumn.equals(orderColumn)) {
                return type;
            }
        }
        return BrandMarketSortOrderType.ORDER_SELLACOUNT_DESC;
    }
}
